package com.example.smartlearning.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.smartlearning.dao.AnswerDao;
import com.example.smartlearning.dao.CollectionDao;
import com.example.smartlearning.entity.AnswerEntity;
import com.example.smartlearning.entity.LessonCollectionEntity;
import com.example.smartlearning.entity.ResultEntity;
import com.example.smartlearning.service.AnswerService;
import com.example.smartlearning.service.CollectionService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class AnswerServiceImpl extends ServiceImpl<AnswerDao, AnswerEntity> implements AnswerService {

    private static final Logger logger = LoggerFactory.getLogger(AnswerServiceImpl.class);//日志。getLogger需要传入当前的类名

    @Resource
    AnswerDao answerDao;

    /**
     * 根据标签查询问题
     *
     * @param tab   标签
     * @param start 开始位置
     * @param limit 限制
     * @return 返回
     */
    @Override
    public String selectAllByTab(String tab, int start, int limit) {
        try {
            System.out.println(answerDao.selectAllByTab(tab,start,limit));
            return ResultEntity.success(answerDao.selectAllByTab(tab, start, limit));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    /**
     * 删除问题
     *
     * @param answerId 问题id
     * @return 返回
     */
    @Override
    public String deleteAnswer(int answerId) {
        try {
            return ResultEntity.success(answerDao.deleteAnswer(answerId));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }


}
